﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>配置信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/lib/layui/css/layui.css" media="all">
    <script src="~/lib/layui/layui.js" charset="utf-8"></script>
</head>
<body>
        <form lay-filter="pzxx" class="layui-form layui-form-pane" action="">
            <input type="hidden" name="id">
            <input type="hidden" name="jbxxid">

            <div class="layui-form-item">
            <!--配置时间-->
                <div class="layui-inline">
                    <label class="layui-form-label">配置时间:</label>
                    <div class="layui-input-inline">
                    <input type="text" name="pzdate" class="layui-input" id="pztime" lay-verify="required" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">
            <!--配置类型-->
            <div class="layui-form-item">   
                <div class="layui-inline">
                <label class="layui-form-label">配置类型</label>
                    <div class="layui-input-inline">
                        <select name="pztype" lay-verify="required" lay-search="">
                            <option value="">下拉选择</option>
                            <option value="晋升">晋升</option>
                            <option value="降职">降职</option>
                            <option value="借调">借调</option>
                            <option value="委派">委派</option>
                            <option value="岗位调整">岗位调整</option>
                            <option value="入职">入职</option>
                        </select>
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <!--单位-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">单位</label>                
                    <div class="layui-input-inline">
                        <input type="hidden" name="pzgs" />
                    <input name="dw" placeholder="选择单位" class="layui-input" lay-verify="required" id="gsxz">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">部门</label>
                    <div class="layui-input-inline">
                        <input name="pzbm" placeholder="填写部门" class="layui-input">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <!--岗位-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">岗位</label>
                    <div class="layui-input-inline">
                    <input type="text" name="pzgw" class="layui-input" lay-verify="required">
                </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <!--行政级别-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">行政级别</label>
                    <div class="layui-input-inline">
                        <select name="xzjb" lay-verify="required" lay-search="">
                            <option value="">下拉选择</option>
                            <option value="总经理">总经理</option>
                            <option value="副总经理">副总经理</option>
                            <option value="总经理助理">总经理助理</option>
                            <option value="部长">部长</option>
                            <option value="副部长">副部长</option>
                            <option value="部长助理">部长助理</option>
                            <option value="主任">主任</option>
                            <option value="副主任">副主任</option>
                            <option value="一级主管">一级主管</option>
                            <option value="二级主管">二级主管</option>
                            <option value="专员">专员</option>
                        </select>
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <!--配置原因-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">配置原因</label>
                    <div class="layui-input-inline">
                    <input type="text" name="pznote" class="layui-input" width="800">
                    </div>
                </div>
            </div>
            <hr class="layui-border-green">

            <div class="layui-form-item">
                 <button type="button" class="layui-btn" id="Save_pzxx">保存</button>
            </div>
            <hr class="layui-border-green">
        </form>
        <script>
        layui.use(['form', 'util', 'laydate', 'dropdown'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var util = layui.util;
            var dropdown = layui.dropdown;
            var laydate = layui.laydate;

            //初始赋值
            var url = location.search; 
            if (url.indexOf("?") != -1) {
                var id = getQueryVariable('id');
                var jbxxid = getQueryVariable('jbxxid');
                if(id!=null)
                {
                    var data = getpzData("", id);
                    form.val('pzxx', {
                        "id": id,
                        "jbxxid": data[0].jbxxid,
                        "pzdate": data[0].pzdate,
                        "pztype": data[0].pztype,
                        "pzgs": data[0].pzgs,
                        "pzbm": data[0].pzbm,
                        "dw": GetOrgInfo(data[0].pzgs),
                        "pzgw": data[0].pzgw,
                        "xzjb": data[0].xzjb,
                        "pznote": data[0].pznote
                    });
                }else
                {
                    form.val('pzxx', {
                        "jbxxid": jbxxid
                    });
                }

            }

            //绑定输入框
            dropdown.render({
                elem: '#gsxz'
                , data: getOrgTreeData()
                , click: function (obj) {
                    this.elem.val(obj.title);
                    form.val('pzxx', {
                        "pzgs": obj.id
                    });
                }
                , style: 'width: 235px;'
            });

            //配置信息保存
            layui.$('#Save_pzxx').on('click', function () {
                var opurl = "/HmcWH/Save_pzxx";

                if (form.val('pzxx').id != "") {
                    opurl = "/HmcWH/Update_pzxx";
                } else {
                    form.val('pzxx', {
                        "id": guiid()
                    });
                }
                var data = form.val('pzxx');

                if (data.jbxxid == "") {
                    layer.msg("请先保存基本信息!");
                    return;
                }

                $.ajax({
                    url: opurl,
                    type: "post",
                    async: false,
                    data: data,
                    success: function (result) {
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg(result, { time: 1000 });
                        if (result == "保存成功！" || result == "修改成功！") {
                            //刷新父级表格
                            parent.layui.table.reload('pzxx', {
                                data: getpzData(data.jbxxid, "")
                            });
                        }
                        if(result=="保存失败"){
                            form.val('pzxx', {
                                "id": guiid()
                            });
                        }
                        parent.layer.close(index);
                    }
                });                                              
            });
        });

        function getOrgTreeData() {
            var data = [];
            $.ajax({
                url: "/HmcWH/GetOrgTreeData",
                type: "post",
                async: false,
                success: function (resut) {
                    data = resut;
                }
            });
            return data;
        }

        function guiid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
                function (c) {
                    var r = (Math.random() * 16) | 0,
                        v = c == 'x' ? r : (r & 0x3) | 0x8;
                    return v.toString(16);
                }
            );
        }

        function getpzData(jbxxid, id) {
            var data = [];
            $.ajax({
                url: "/HmcWH/get_pzxx",    //后台数据请求地址
                type: "post",
                async: false,
                data: { "jbxxid": jbxxid, "pzxxid": id },
                success: function (resut) {
                    data = resut;
                }
            });
            return data;
        }

        function GetOrgInfo(OrgId) {
            var data = "";
            $.ajax({
                url: "/TreeData/GetOrgInfo",
                type: "post",
                data: { "OrgId": OrgId },
                async: false,
                success: function (resut) {
                    data = resut;
                }
            });
            return data;
        }

        function getNow() {
            var nowdate = new Date();
            var year = nowdate.getFullYear(),
                month = nowdate.getMonth() + 1,
                date = nowdate.getDate();

            return year+"-"+month+"-"+date;
        }

        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return pair[1]; }
            }
            return null;
        }
        </script>

</body>
</html>